﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;
using System.Data;

namespace IHISCETeim.Web.MachineSys.MacModel
{
    public partial class OJobList : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.查看, Permission.修改, Permission.新增, Permission.删除 };
            }
        }
        protected override string DWZRef
        {
            get
            {
                return "OJobList";
            }
        }

        #region 属性 (查询条件)


        protected string CommonFiled
        {
            get
            {
                return GetRequestValue<string>("CommonFiled","");

            }
        }
        protected string CommonValue
        {
            get
            {
                return GetRequestValue<string>("CommonValue","");

            }
        }

        protected string MachineType
        {
            get
            {
                return GetRequestValue<string>("MachineType","");
            }
        }
        protected string DownlineDateFrom
        {
            get
            {
                return GetRequestValue<string>("DownlineDateFrom", "");

            }
        }
        protected string DownlineDateTo
        {
            get
            {
                return GetRequestValue<string>("DownlineDateTo", "");

            }
        }

        protected string beforeInStorageDate
        {
            get
            {
                return GetRequestValue<string>("beforeInStorageDate","");
            }
        }

        protected string Remark
        {
            get
            {
                return GetRequestValue<string>("Remark", "");
            }
        }

        protected override string orderField
        {
            get
            {
                return string.IsNullOrEmpty(base.orderField) ? "SerialNumber" : base.orderField;
            }
        }
        protected override string orderDirection
        {
            get
            {
                return string.IsNullOrEmpty(base.orderDirection) ? "Desc" : base.orderDirection;
            }
        }
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            //if (GetRequestValue<string>("ajaxmethod", "") == "getmactypehtml")
            //{
            //    Response.Write(GetMacTypeHtml());
            //    Response.End();
            //}
            //if (GetRequestValue<string>("ajaxmethod", "") == "getyesnoenumhtml")
            //{
            //    Response.Write(getyesnoenumhtml());
            //    Response.End();
            //}
            //if (GetRequestValue<string>("ajaxmethod", "") == "editjob")
            //{
            //    Response.Write(editjob());
            //    Response.End();
            //}
            DataBind();
            this.AddLog(Permission.查看, GetWhereSql());
        }

        protected DataTable sumdt = null;

        protected string GetWhereSql()
        {
            string wheresql = QueryOperatorsEnumHelper.ConvertCommonOperator(CommonFiled, QueryOperatorsEnum.包含, CommonValue);
            string DOWNSQL = QueryOperatorsEnumHelper.ConvertCommonOperator("DownlineDate", QueryOperatorsEnum.范围, DownlineDateFrom + "|" + DownlineDateTo);

            if (!string.IsNullOrEmpty(wheresql) && !string.IsNullOrEmpty(DOWNSQL))
            {
                wheresql += " and " + DOWNSQL;
            }
            else if (!string.IsNullOrEmpty(DOWNSQL))
            {
                wheresql = DOWNSQL;
            }


            if (!MachineType.IsEmptyOrNull())
            {
                if (string.IsNullOrEmpty(wheresql))
                    wheresql = " MachineType='" + MachineType + "'";
                else
                    wheresql += " and MachineType='" + MachineType + "'";
            }

            if (!beforeInStorageDate.IsEmptyOrNull())
            {
                if (string.IsNullOrEmpty(wheresql))
                    wheresql = " OnlineDate>='" + beforeInStorageDate + "'";
                else
                    wheresql += " and OnlineDate>='" + beforeInStorageDate + "'";
            }


            if (!Remark.IsEmptyOrNull())
            {
                if (string.IsNullOrEmpty(wheresql))
                    wheresql = " Remark like '%" + Remark + "%'";
                else
                    wheresql += " and Remark like '%" + Remark + "%'";
            }

            return wheresql;
        }

        private void DataBind()
        {
            if (MachineType == "JK")
            {
                this.rpMenuJK.DataSource = OJobJinKouController.GetAllList();
                this.rpMenuJK.DataBind();
            }
            else
            { 
                
                DataTableCollection dtc = OJobController.GetPagination(GetWhereSql(), pageNum, numPerPage, SQLSort, ref TotalCount);
                this.rpMenu.DataSource = dtc[0];
                this.rpMenu.DataBind();
                sumdt = dtc[1];
            }
        }

        #region 列表编辑相关方法
        /*
        private string GetMacTypeHtml()
        { 
            string selectValue=GetRequestValue<string>("selectValue","");
            string html= GetMacType("select", "MachineType", selectValue);
            return html;
        }

        private string getyesnoenumhtml()
        {
            bool selectValue = GetRequestValue<bool>("selectValue",false);
            string inputName = GetRequestValue<string>("inputName", "");
            string html =string.Format( "<select class='combox' name='{0}'>",inputName);
            html += string.Format("<option value='True' {0}>是</option>", selectValue?"selected":"");
            html += string.Format("<option value='False' {0}>否</option>", selectValue ? "" : "selected");
            html += "</select>";
            return html;
        }

        private string editjob()
        {
            OJobInfo obj = Request.SerializableObject<OJobInfo>();

            //if (OUserController.CheckUserName(obj.UserName))
            //{
            //    AlertJson("登陆帐户名已存在,请重新输入.");
            //    return;
            //}
            string trinnerhtml = "";
            bool e = OJobController.Update(obj);
            if (!e)
                return "";//表示失败
            /*
             <td><%# Eval("MachineType")%></td>
				<td tdvalue="<%# Eval("SerialNumber")%>">
                <a target="navTab" title="查看作业日报表" rel="viewdailyjob" fresh="true" href="MacModel/ODailyList.aspx?SerialNumber=<%# Eval("SerialNumber") %>"><%# Eval("SerialNumber")%></a>
                </td>
                <td tdvalue="<%# Eval("PID")%>">
                    <a target="navTab" title="查看项目" rel="OProjectList" fresh="true" href="MacModel/OProjectList.aspx?PNAME=<%# Eval("PNAME") %>"><%# Eval("PNAME")%></a>
                 </td>
				<td><%# Eval("EngineNumber")%></td>
                <td><%# Eval("DownlineDate") is DBNull ? "" : Convert.ToDateTime(Eval("DownlineDate")).ToString("yyyy-MM-dd")%></td>
				<td  tdvalue="<%# Eval("GPSIsSetUp")%>"><%# Eval("GPSIsSetUp") is DBNull ? "" : Convert.ToBoolean(Eval("GPSIsSetUp")) ? "有" : "<b style='color:red;'>无</b>"%></td>
                <td><%# Eval("InStorageDate") is DBNull ? "" : Convert.ToDateTime(Eval("InStorageDate")).ToString("yyyy-MM-dd")%></td>
                <td><%# Eval("GPSNumber")%></td>
                <td><%# Eval("OnlineDate") is DBNull ? "" : Convert.ToDateTime(Eval("OnlineDate")).ToString("yyyy-MM-dd")%></td>
                <td tdvalue="<%# Eval("GPSOutStorage")%>"><%# Eval("GPSOutStorage") is DBNull ? "" : Convert.ToBoolean(Eval("GPSOutStorage")) ? "是" : "<b style='color:red;'>否</b>"%></td>
                <td tdvalue="<%# Eval("MACStock")%>"><%# Eval("MACStock") is DBNull ? "" : Convert.ToBoolean(Eval("MACStock")) ? "是" : "<b style='color:red;'>否</b>"%></td>
                <td tdvalue="<%# Eval("GPSStock")%>"><%# Eval("GPSStock") is DBNull ? "" : Convert.ToBoolean(Eval("GPSStock")) ? "是" : "<b style='color:red;'>否</b>"%></td>
                <td><%# Eval("OutStockType")%></td>
                <td><%# Eval("AgentName")%></td>
                <td><%# Eval("Remark")%></td>
             
             
               trinnerhtml=string.Format("<td>{0}</td>",obj.MachineType);
			   trinnerhtml+=string.Format("<td tdvalue=\"{0}\">{0}</td>",obj.SerialNumber);
               trinnerhtml+=string.Format("<td tdvalue=\"{0}\">{1}</td>",GetRequestValue<int>("PID",0),OProjectController.GetById(GetRequestValue<int>("PID",0)).PName);
			   trinnerhtml+=string.Format("<td>{0}</td>",obj.EngineNumber);
               trinnerhtml+=string.Format("<td>{0}</td>",obj.DownlineDate);
			   trinnerhtml+=string.Format("<td  tdvalue=\"{0}\">{1}</td>",obj.GPSIsSetUp,obj.GPSIsSetUp ? "有" : "<b style='color:red;'>无</b>");
                trinnerhtml+=string.Format("<td>{0}</td>",obj.InStorageDate);
               trinnerhtml+=string.Format("<td>{0}</td>",obj.GPSNumber);
                trinnerhtml+=string.Format("<td>{0}</td>",obj.OnlineDate);
             trinnerhtml+=string.Format("<td tdvalue=\"{0}\">{1}</td>",obj.GPSOutStorage,obj.GPSOutStorage ? "有" : "<b style='color:red;'>无</b>");
              trinnerhtml+=string.Format("<td tdvalue=\"{0}\">{1}</td>",obj.MACStock,obj.MACStock ? "有" : "<b style='color:red;'>无</b>");
              trinnerhtml+=string.Format("<td tdvalue=\"{0}\">{1}</td>",obj.GPSStock,obj.GPSStock ? "有" : "<b style='color:red;'>无</b>");
               trinnerhtml+=string.Format("<td>{0}</td>",obj.OutStockType);
              trinnerhtml+=string.Format("<td>{0}</td>",obj.AgentName);
              trinnerhtml+=string.Format("<td>{0}</td>",obj.Remark);

            return trinnerhtml;
        }
    */
        #endregion

        protected object GetCountByFiled(string FiledName)
        {
            return sumdt.Rows[0][FiledName];

            //return OJobController.GetCountByFiled(FiledName);
        }
    }
}